package com.ruicar.afs.cloud.batch.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruicar.afs.cloud.batch.entity.AfsBatchInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Map;

public interface AfsBatchInfoMapper extends BaseMapper<AfsBatchInfo> {
    @Select("select system_name as systemName,last_work_day as lastWorkDay,holiday_mode as holidayMode,batch_date as batchDate,last_batch_date as lastBatchDate,system_status as systemStatus,live_thread_num as liveThreadNum,error_notice_config as errorNoticeConfig,batch_type as batchType from afs_batch_info batchDate where batchDate.system_name=#{systemName} for update")
    Map selectSystem(@Param("systemName") String systemName);


    @Select("select system_name as systemName,last_work_day as lastWorkDay,holiday_mode as holidayMode,batch_date as batchDate,last_batch_date as lastBatchDate,system_status as systemStatus,live_thread_num as liveThreadNum,error_notice_config as errorNoticeConfig,batch_type as batchType  from afs_batch_info batchDate where batchDate.system_name=#{systemName}")
    Map querySystemNameWithUpdate(@Param("systemName") String systemName);

    @Update("update afs_batch_info set live_thread_num=live_thread_num+${num} where system_name=#{systemName}")
    int addRunThreadNum(@Param("systemName") String systemName,@Param("num") int num);


    @Update("update afs_batch_info set live_thread_num=live_thread_num-${num} where system_name=#{systemName}")
    int cutDown(@Param("systemName") String systemName,@Param("num") int num);
}
